package my.interview;

import java.util.*;

public class Main2 {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String str = scanner.nextLine();
        String result = solution(str);
        System.out.println(result);
    }

    private static String solution(String line) {
        String[] split = line.split(" ");
        Arrays.sort(split);
        TreeSet<String> treeSet = new TreeSet<>(Arrays.asList(split));
        TreeSet<String> res = new TreeSet<>();
        boolean flag = false;
        for (int i = split.length - 1; i >= 0; i--) {
            String pw = split[i];
            String tmp = pw.substring(0, pw.length() - 1);

            while (tmp.length() > 0) {
                if (flag = treeSet.contains(tmp)) {
                    tmp = tmp.substring(0, tmp.length() - 1);
                    res.add(pw);
                } else {
                    break;
                }
            }
        }
        if (flag) {
            return res.last();
        }else {
            return "";
        }
    }
}
